 package com.suozq.nio;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * @author 锁战强
 * @date 2022/04/07
 */
public class BlockClient {
    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress(6666));
//        socketChannel.configureBlocking(false);
        FileChannel fileChannel = FileChannel.open(Paths.get("G:/test.txt"), StandardOpenOption.READ);
        fileChannel.transferTo(0, fileChannel.size(), socketChannel);
        fileChannel.close();
        socketChannel.shutdownOutput();
        ByteBuffer bb = ByteBuffer.allocate(1024);
        while(socketChannel.read(bb)>-1) {
            bb.flip();
            System.out.print(new String(bb.array()));
            bb.clear();
        }
        socketChannel.close();
    }
}
